<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<div th:include="~{main/index :: nav}"></div>
<h1>课程管理</h1>
<hr>
<div style="display: flex;justify-content: space-around;">
    <div style="width: 60%; border: 1px;">
        <table class="table table-hover table-striped table-bordered" border="1" width="90%" style="text-align: center">
            <tr style="background-color: #ccd3d2">
                <th>课程编号</th>
                <th>课程名称</th>
                <th>课程修改</th>
                <th>课程删除</th>
            </tr>
            <tr th:each="c:${courses}">
                <td th:text="${c.cno}"></td>
                <td th:text="${c.cname}"></td>
                <td><a th:href="'/adm/course/go2update?cno='+ ${c.cno} + '&curPage='+ ${curPage}"><button class="btn btn-warning">修改</button> </a></td>
                <td><a th:href="@{'/adm/course/delete?cno='+ ${c.cno}} + '&curPage='+ ${curPage}"><button class="btn btn-warning">删除该课程</button> </a> </td>
            </tr>
        </table>

        <p style="text-align: center">
            <a th:if="${curPage-1} ge 1"  th:href="@{'/adm/course/prevPage?curPage='+ ${curPage-1}}">上一页</a>
            <a th:if="${curPage-1} lt 1"  th:href="@{'/adm/course/prevPage?curPage=1'}">上一页</a>
            <span th:text="${curPage} +'/'+${totalPage}"/>
            <a th:if="${curPage+1} le ${totalPage}" th:href="@{'/adm/course/nextPage?curPage='+ ${curPage+1}}">下一页</a>
            <a th:if="${curPage+1} gt ${totalPage}"  th:href="@{'/adm/course/nextPage?curPage=' + ${totalPage}}">下一页</a>
        </p>
    </div>

    <div style="width: 38%">
        <a th:href = "'/adm/course/go2Add/'+${curPage}"><button class="btn btn-warning">添加一个新的课程</button></a>
        <hr>
        <form th:action="'/adm/course/'+${action} + '?curPage='+ ${curPage}" method="post">
            <table class="table table-hover table-striped table-bordered">
                <tr>
                    <th style="width: 40%">课程编号：</th>
                    <td><input th:value="${cou.cno}" type="text" name="cno" th:readonly="${action eq 'update'}"></td>
                </tr>
                <tr>
                    <th style="width: 40%">课程名称：</th>
                    <td><input  th:value="${cou.cname}" type="text"name="cname"></td>
                </tr>
                <tr>
                    <th style="width: 40%"></th>
                    <td>
                        <button th:if="${action eq 'doAdd'}"  class="btn btn-warning">添加</button>
                        <button th:if="${action eq 'update'}" class="btn btn-warning">修改课程</button>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>
<span th:text="${state}"></span>
</body>
</html>